/**
 * Welcome screen
 */
var launcher = {
	
	bind : function() {
		debug.print("launcher.bind");
		
		$("#launcher-field input").attr("value", config.launcher_input_text);
		
		// init manual opacity
		if (check.browser != 'msie') {
			$("#launcher-manual").css("opacity", 1);
			$("#launcher").hover(function(){
				$("#launcher-manual").css("opacity", null);
			});
		}
		
		$("#launcher-manual > a").click(function() {
			launcher.close();
			$("#search-field input").focus();
		});
		
		$("#launcher-field input").focus(function() {
			$(this).attr("value", "");
		});
		
		$("#launcher-field input").keydown(function(e) {
			if (e.keyCode === 13) {
				launcher.startWithSearch();
			}
		});
		$("#launcher-button").click(function() {
			launcher.startWithSearch();
		});
		
		$("#launcher-playlist li").click(function() {
			launcher.startWithPlaylist($(this).attr("id").substr(9,1));
		});		
	},
	
	startWithSearch : function() {
		debug.print("launcher.startWithSearch");
		var search = $("#launcher-field input").attr("value");
		if (!search || search == config.launcher_input_text) {
			return flash.flash("No search","query given");
		}
		this.wait();
		controller.beLucky(search, function(status) {
			if (status == 'ok') {
				launcher.close();
			} else {
				launcher.unWait();
			}
		});		
	},
	
	startWithPlaylist : function(id) {
		debug.print("launcher.startWithPlaylist [id: "+id+"]");
		this.wait();
		playlist.load(id, function() {
			launcher.close();
			autodj.enable();
		});
	},
	
	wait : function() {
		debug.print("launcher.wait");
		$("#launcher-wait").show();
	},
	
	unWait : function() {
		debug.print("launcher.unWait");
		$("#launcher-wait").hide();
	},
	
	show : function() {
		debug.print("launcher.show");
		var me = $("#launcher");
		flash.center(me);
		$("#modal-bg").show();
		if (check.browser == 'msie') {
			me.show();
		} else {
			me.fadeIn(500);
		}		
	},
	
	close : function() {
		debug.print("launcher.close");
		var me = $("#launcher");
		$("#modal-bg").hide();
		if (check.browser == 'msie') {
			me.hide();
		} else {
			me.fadeOut(150);
		}		
	}
	
}
